import { CreateAxiosDefaults } from "axios";

export interface SSEMessage<T = unknown> {
  id: string
  event: string
  data: T
  retry?: number
  timestamp: number
}

export type SSEStatus = 
  | 'CONNECTING'
  | 'OPEN'
  | 'CLOSED'
  | 'ERROR'

export interface SSEOptions {
  url: string
  autoConnect?: boolean
  withCredentials?: boolean
  retryInterval?: number
  heartbeatInterval?: number
}

export type AxiosConfig = {
  url: string;
  method: string;
  params?: object;
  data?: object;
  formData?: object;
};

export type MyCreateAxiosDefaults = CreateAxiosDefaults & {
  retries: number;
};

export type Dictionary<T> = {
  [key: string | number]: T;
};

export type IdGenerator = { [key: string]: number };

export type LocalConfig = {
  language: string;
};

export type I18nPackage = {
  cn: Dictionary<string>;
  en: Dictionary<string>;
};

export type Token = {
  accessToken: string;
  expire: number;
  refreshToken: string;
};

export type IconConfig = {
  name: string; // 图标名称
  rotating?: boolean; // 是否旋转
  size?: string; // 大小
  customSize?: string; // 自定义大小
  type: string; // 类别
};

export type FormItem = {
  field: string; // 属性名
  type: "input" | "select" | "checkbox" | "radio"; // 表单项类型
  value: any | Array<any>; // 值
  dataSource?: Function; // 数据源
  onChange?: Function; // 值改变事件
  onInput?: Function; // 输入事件
  prev: FormItem; // 上一个组件
  next: FormItem; // 下一个组件
};

export type Form = {
  url: string; // 提交服务器地址
  method: "post" | "get"; // 提交方法
  data: any; // 提交数据
  params: any; // 提交参数
  root: FormItem; // 表单项
};
